//
//  EvaluateController.m
//  FD
//
//  Created by Yasin on 2018/10/16.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//
//星级评分按钮高度
#define kEvaluateViewHeight 40

#import "EvaluateController.h"
//view
#import "EvaluateItemView.h"
#import "EvaluatePhoneItemCell.h"
#import "PlaceholderTextView.h"

//tools
#import "TZImagePickerController.h" //11-12 图片选择器
#import <MobileCoreServices/MobileCoreServices.h>
#import <AWSS3/AWSS3.h> //11-13 亚马逊云存储s3

#import "FDCustomAlertView.h" //1-2个人资料专用弹框

@interface EvaluateController ()<UICollectionViewDelegate,UICollectionViewDataSource,
TZImagePickerControllerDelegate,
UIImagePickerControllerDelegate,
UINavigationControllerDelegate,
UICollectionViewDelegateFlowLayout
>

/**第一部分: 服务、口味、骑手*/
@property (nonatomic,  strong) UIView *div1;
/**第二部分:写下你的评价*/
@property (nonatomic,  strong) UIView *div2;
/**意见反馈输入框1-22*/
@property (nonatomic, strong) PlaceholderTextView *fadeBackTextView;

/**第三部分:上传图片 里面放的是 collectionView */
@property (nonatomic,  strong) UIView *div3;
/**第三部分:collectionView*/
@property (nonatomic,  strong) UICollectionView *clv;
/**提交按钮*/
@property (nonatomic,  strong) UIButton *tijiaoBtn;
/**11-12*/
@property (nonatomic, strong) UIImagePickerController *imagePickerVc;

/**圖片數組*/
@property (nonatomic, strong) NSMutableArray *dataArr;

/**定义变量标记是否全部都上传成功 没成功一次 count++,如果totalCount = self.dataArr.count
 说明最后一个也上传成功了*/
@property (nonatomic) NSInteger totalCount;


//默认都是5星好评
/**1.综合*/
@property (nonatomic) NSInteger compreScore;
/**2.综合*/
@property (nonatomic) NSInteger serviceScore;
/**3.综合*/
@property (nonatomic) NSInteger flavorScore;
/**4-1.综合*/
@property (nonatomic) NSInteger enviromentScore;
/**4-2.综合*/
@property (nonatomic) NSInteger riderScore;


/**1.服务评分 不选默认好评 5*/
@property (nonatomic) NSInteger fuwuScore;
/**2.口味评分 5*/
@property (nonatomic) NSInteger kouweiScore;
/**3.骑手评分 5*/
@property (nonatomic) NSInteger qishouScore;
@end


@implementation EvaluateController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = NSLocalizedString(L_PJ_FaBiaoPinLin, @"发表评论");
    //服务、口味、骑手
    [self setupUpView1];
    [self setupCenterView]; //评论
    [self setupAddPhoto]; // 添加图片
    
    
    //提交按钮:
    self.tijiaoBtn.frame = CGRectMake(10, self.div3.rb_bottom + FDScaleWidth(50), SCREEN_WIDTH - 20, 40);
    [self.view addSubview:self.tijiaoBtn];
    
    self.totalCount = 0;//初始0
    
    FDLog(@"====:%@",self.userOrderId);
    
    
    //默认五星好评
    self.compreScore = 5;
    self.serviceScore = 5;
    self.flavorScore = 5;
    self.enviromentScore = 5;
    self.riderScore = 5; //默认都是5星好评
}

//第一部分
- (void)setupUpView1 {
//  如果订单为门店预约、自提，则显示评星为：综合、服务、口味、环境，一共4个评星
//  如果订单为外送，则显示评星为：综合、服务、口味、骑手，一共4个评星
//  前3个评星相同（综合、服务、口味），最后一个骑手/环境，根据订单种类决定
    
    //一、======创建
    //ipheonX  刘海
    self.div1 = [[UIView alloc] initWithFrame:CGRectMake(0, FD_NavH, SCREEN_WIDTH, 160)];
    [self.view addSubview:self.div1];
    
    
    //国际化
    NSString *zhStr = [NSString stringWithFormat:@"%@:",NSLocalizedString(L_PJ_ZongHe, @"综合")];
    NSString *fwStr = [NSString stringWithFormat:@"%@:",NSLocalizedString(L_PJ_FuWu, @"服务")];
    NSString *kwStr = [NSString stringWithFormat:@"%@:",NSLocalizedString(L_PJ_KouWei, @"口味")];
    NSString *hjStr = [NSString stringWithFormat:@"%@:",NSLocalizedString(L_PJ_HuanJing, @"环境")];
    NSString *qsStr = [NSString stringWithFormat:@"%@:",NSLocalizedString(L_PJ_QiShou, @"骑手")];
    
    EvaluateItemView *comprehensionView = [[EvaluateItemView alloc] initWithFrame:CGRectMake(0, 0 , SCREEN_WIDTH, kEvaluateViewHeight) title:zhStr];
    FDWeakSelf;
    comprehensionView.currentScoreBlock = ^(NSInteger currentScore) {
        weakSelf.compreScore = currentScore;
    };
    
    EvaluateItemView *serviceView = [[EvaluateItemView alloc] initWithFrame:CGRectMake(0, comprehensionView.rb_bottom, SCREEN_WIDTH, kEvaluateViewHeight) title:fwStr];
    serviceView.currentScoreBlock = ^(NSInteger currentScore) {
        weakSelf.serviceScore = currentScore;
    };
    
    EvaluateItemView *flavorView = [[EvaluateItemView alloc] initWithFrame:CGRectMake(0, serviceView.rb_bottom, SCREEN_WIDTH, kEvaluateViewHeight) title:kwStr];
    flavorView.currentScoreBlock = ^(NSInteger currentScore) {
        weakSelf.flavorScore = currentScore;
    };
    
    
    EvaluateItemView *enviromentView = [[EvaluateItemView alloc] initWithFrame:CGRectMake(0, flavorView.rb_bottom, SCREEN_WIDTH, kEvaluateViewHeight) title:hjStr];
    enviromentView.currentScoreBlock = ^(NSInteger currentScore) {
        weakSelf.riderScore = currentScore;
        weakSelf.enviromentScore = currentScore;
    };
    
    //外送(0)显示骑手评分
    if (self.fdDeliveryType == FDDeliveryTypeWaiSong) {
        enviromentView.nameLb.text = qsStr;
    }else if(self.fdDeliveryType == FDDeliveryTypeZiTi ||
             self.fdDeliveryType == FDDeliveryTypeMenDianYuYue){ //自提(1)、门店预约(2) 显示环境评分
        enviromentView.nameLb.text = hjStr;
    }
    
    
    //灰色的线
    UIView *graylineView = [[UIView alloc] initWithFrame:CGRectMake(10, enviromentView.rb_bottom + 5 , SCREEN_WIDTH - 20, 1)];
    graylineView.backgroundColor = kMainLightGrayColor;

    //二、======添加到view上。
    [self.div1 addSubview:comprehensionView];
    [self.div1 addSubview:serviceView];
    [self.div1 addSubview:flavorView];
    [self.div1 addSubview:enviromentView];
    [self.div1 addSubview:graylineView];
}

//设置中间的view第二部分
- (void)setupCenterView {
    self.div2 = [[UIView alloc] initWithFrame:CGRectMake(10, self.div1.rb_bottom + 10, SCREEN_WIDTH, 100)];
    [self.view addSubview:self.div2];
    
    PlaceholderTextView *textView = [[PlaceholderTextView alloc] initWithFrame:self.div2.bounds];
    
    NSString *pleaseInputYouEvaluateStr = @"Please write down your comments.";
    if ([NSString rb_ChineseLanguage]) {
        pleaseInputYouEvaluateStr = @"请写下你的评价";
    }
    textView.placeholder = pleaseInputYouEvaluateStr;
    
    textView.font = [UIFont systemFontOfSize:15.0];
    self.fadeBackTextView = textView;
    [self.div2 addSubview:textView];
}

//第三部分
- (void)setupAddPhoto {
    self.div3 = [[UIView alloc] initWithFrame:CGRectMake(10, self.div2.rb_bottom+5, SCREEN_WIDTH - 20, 100)];
//    self.div3.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.div3];
    
    self.clv.frame = self.div3.bounds;
//    self.clv.layer.borderColor = [UIColor redColor].CGColor;
//    self.clv.layer.borderWidth = 1.0;
    [self.div3 addSubview:self.clv];
}

- (UICollectionView *)clv {
    if (!_clv) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        
        _clv = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        //代理
        _clv.delegate = self;
        _clv.dataSource = self;
        //设置背景
        _clv.backgroundColor = [UIColor whiteColor];
        _clv.showsVerticalScrollIndicator = NO; //影藏滚动条
        _clv.scrollEnabled = NO; //不让滚
        
        //注册item
        [_clv registerClass:[EvaluatePhoneItemCell class] forCellWithReuseIdentifier:@"EvaluatePhoneItemCell"];
    }
    return _clv;
}
- (NSMutableArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

- (UIButton *)tijiaoBtn {
    if (!_tijiaoBtn) {
        _tijiaoBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        
        [_tijiaoBtn setTitle:NSLocalizedString(Submit, @"提交") forState:(UIControlStateNormal)];
        [_tijiaoBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [_tijiaoBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateHighlighted)];
        _tijiaoBtn.backgroundColor = kMainRedColor;
        _tijiaoBtn.layer.masksToBounds = YES;
        _tijiaoBtn.layer.cornerRadius  = 5;
        [_tijiaoBtn addTarget:self action:@selector(clickTiJiaoBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _tijiaoBtn;
}



#pragma  mark - 上传图片collectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArr.count + 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    EvaluatePhoneItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"EvaluatePhoneItemCell" forIndexPath:indexPath];
    if (indexPath.row == self.dataArr.count) {
        cell.iv.image = [UIImage imageNamed:@"tianJiaZhaoPian.png"];
        cell.deleteBtn.hidden = YES;
        cell.lightbgView.hidden = YES;
    }else {
        cell.iv.image = self.dataArr[indexPath.row]; //赋值
        cell.deleteBtn.hidden = NO;
        cell.lightbgView.hidden = NO;
    }
    return cell;
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CGFloat w = (self.clv.bounds.size.width - 5*3) / 4;
    FDLog(@"%@",NSStringFromCGRect(self.view.bounds));
    FDLog(@"%f",w);
    return CGSizeMake(w, w);
}
//一行显示4个
//InteritemSpacing---->左右间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 5;
}

//LineSpacing 上下间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 100;
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == self.dataArr.count) { //选择照片

        [self showSelectPicAlert];
        
    }else { //删除照片
        UIImage *selectedImg = self.dataArr[indexPath.row];
        [self.dataArr removeObject:selectedImg];
        [self.clv reloadData]; //刷新
    }
}


- (void)showSelectPicAlert {
    //国际化
    NSString *pzStr = NSLocalizedString(TakePhoto, @"拍照");
    NSString *cxczxzStr = NSLocalizedString(SelectFromAlbum, @"从相册选择");
    
    [FDCustomAlertView showAlertWithTitleArr:@[pzStr,cxczxzStr] complectionBlock:^(NSInteger index, NSString * _Nonnull selectValue) {
        if (index==0) {
            //            [self pushImagePickerController];
            [self takePhoto];
        }else {
            [self pushTZImagePickerController];
        }
    }];
}







#pragma mark - 图片选择器 三方
#pragma mark - UIImagePickerController
- (UIImagePickerController *)imagePickerVc {
    if (_imagePickerVc == nil) {
        _imagePickerVc = [[UIImagePickerController alloc] init];
        _imagePickerVc.navigationBar.barTintColor = self.navigationController.navigationBar.barTintColor;
        _imagePickerVc.navigationBar.tintColor = self.navigationController.navigationBar.tintColor;
        UIBarButtonItem *tzBarItem, *BarItem;
        
        //设置代理2019-2-15
        _imagePickerVc.delegate = self;
        
        tzBarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[TZImagePickerController class]]];
        BarItem = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UIImagePickerController class]]];
        
        NSDictionary *titleTextAttributes = [tzBarItem titleTextAttributesForState:UIControlStateNormal];
        [BarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
    }
    return _imagePickerVc;
}

- (void)takePhoto {
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
        // 无相机权限 做一个友好的提示
        [self permissionAlert];
        
    } else if (authStatus == AVAuthorizationStatusNotDetermined) {
        // fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏
        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
            if (granted) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self takePhoto];
                });
            }
        }];
        // 拍照之前还需要检查相册权限
    } else if ([PHPhotoLibrary authorizationStatus] == 2) { // 已被拒绝，没有相册权限，将无法保存拍的照片
        [self permissionAlert];
        
    } else if ([PHPhotoLibrary authorizationStatus] == 0) { // 未请求过相册权限
        [[TZImageManager manager] requestAuthorizationWithCompletion:^{
            [self takePhoto];
        }];
    } else {
        [self pushImagePickerController];
    }
}

//权限弹框
- (void)permissionAlert {
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
    [alertVc addAction:cancel];
    [self presentViewController:alertVc animated:YES completion:nil];
}


// 调用相机
- (void)pushImagePickerController {
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
        self.imagePickerVc.sourceType = sourceType;
        NSMutableArray *mediaTypes = [NSMutableArray array];
        
        [mediaTypes addObject:(NSString *)kUTTypeImage];
        
        if (mediaTypes.count) {
            _imagePickerVc.mediaTypes = mediaTypes;
        }
        [self presentViewController:_imagePickerVc animated:YES completion:nil];
    } else {
        [JRToast showWithText:@"模拟器中无法打开照相机,请在真机中使用"];
        NSLog(@"模拟器中无法打开照相机,请在真机中使用");
    }
}


//!!!!:从相册中选择
- (void)pushTZImagePickerController {
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:4 columnNumber:3 delegate:self pushPhotoPickerVc:YES];
    // imagePickerVc.navigationBar.translucent = NO;
    
#pragma mark - 五类个性化设置，这些参数都可以不传，此时会走默认设置
    imagePickerVc.videoMaximumDuration = 10; // 视频最大拍摄时间
    [imagePickerVc setUiImagePickerControllerSettingBlock:^(UIImagePickerController *imagePickerController) {
        imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
    }];
    
    imagePickerVc.iconThemeColor = [UIColor colorWithRed:31 / 255.0 green:185 / 255.0 blue:34 / 255.0 alpha:1.0];
    imagePickerVc.showPhotoCannotSelectLayer = YES;
    imagePickerVc.cannotSelectLayerColor = [[UIColor whiteColor] colorWithAlphaComponent:0.8];
    [imagePickerVc setPhotoPickerPageUIConfigBlock:^(UICollectionView *collectionView, UIView *bottomToolBar, UIButton *previewButton, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel, UIView *divideLine) {
        [doneButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    }];
    // 4. 照片排列按修改时间升序
    imagePickerVc.sortAscendingByModificationDate = YES;
    /// 5. 单选模式,maxImagesCount为1时才生效
    imagePickerVc.showSelectBtn = NO;
    imagePickerVc.allowCrop = YES;
    imagePickerVc.needCircleCrop = YES;
    // 设置竖屏下的裁剪尺寸
    NSInteger left = 30;
    NSInteger widthHeight = self.view.rb_width - 2 * left;
    NSInteger top = (self.view.rb_height - widthHeight) / 2;
    imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight);
    
    imagePickerVc.statusBarStyle = UIStatusBarStyleLightContent;
    
    // 设置是否显示图片序号
    imagePickerVc.showSelectedIndex = YES;
#pragma mark - 到这里为止
    // 你可以通过block或者代理，来得到用户选择的照片.
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
//        UIImage *img = [photos firstObject];
        for (UIImage *img in photos) {
            [self.dataArr addObject:img];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.clv reloadData];//
        });
    }];
    
    [self presentViewController:imagePickerVc animated:YES completion:nil];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {

    FDLog(@"拍照选择的图片");
    [picker dismissViewControllerAnimated:YES completion:nil];
    UIImage *pzImg =  info[UIImagePickerControllerOriginalImage];
    
    [self.dataArr addObject:pzImg];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.clv reloadData];
    });
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:nil];
    FDLog(@"点击了取消");
}



#pragma mark  - 调接口
- (void)clickTiJiaoBtnAction:(UIButton *)btn {
    //如果没有图片，上面的事就不用干了
    if (self.dataArr.count) {
    //1.申请要存储图片空间：拿到服务器返回的图片名字数组
        //根据名字上传图片:AWSS3实现,批量上传
        //上传成功之后:调评价接口。
        [self requestAWSS3WithImageArr:self.dataArr];
    }else {
        //直接调接口:评价接口。
        NSDictionary *parDicNoPics = [self assembleSaveEvaluateParDicWithArr:nil];
        [self requestSaveEvaluteWithPardic:parDicNoPics];
    }
}

//向服务器申请：n张图片名字。
- (void)requestAWSS3WithImageArr:(NSArray *)imgArr {
    //如果没有选择照片就,下面的操作就省了。
    if (imgArr.count < 1) return;
    
    [FDHttpAPi requestAWSS3MultipleWithQuantity:imgArr.count successBlock:^(id responseObjc) {
        
        NSString *event = responseObjc[@"event"];
        if ([event isEqualToString:SUCCESS]) {
            //预先返回图片名字,根据这些名字上传图片到亚马逊s3服务器。上传成功之后,
            //在把这些图片传给服务器,上传成功了。
            NSArray *objectkeyArr = responseObjc[@"data"][@"objectKey"];
            
            //亚马逊s3上传图片
            //已知：self.dataArr 和 objectKeyArr的个数是一样的
            for (int i=0; i<objectkeyArr.count; i++) {
                UIImage *img = self.dataArr[i]; //
                //compression Quality:压缩质量
                NSData *imgData = UIImageJPEGRepresentation(img, 0.5);
                [self uploadData:imgData updataPicName:objectkeyArr[i] picNameArr:objectkeyArr];
            }
        }else {
            [JRToast showWithText:responseObjc[describe]];
        }
    } fialBlock:^(NSError *error) {
        FDLog(@"%@",[error localizedDescription]);
    }];
}

/**调用亚马逊的接口,上传图片*/

/**组装请求参数*/
- (NSDictionary *)assembleSaveEvaluateParDicWithArr:(NSArray *)picNameArr{
    
    //组装请求参数
    NSString *userOrderId = self.userOrderId; //1.订单号
    
    
    NSNumber *complexStarLevel = @(self.compreScore);//综合
    NSNumber *serviceStarLevel = @(self.serviceScore); //.服务评分
    NSNumber *tasteStarLevel = @(self.flavorScore); //.口味评星
    NSNumber *surroundingStarLevel = @(self.enviromentScore); //.环境评星
    NSNumber *deliveryStarLevel = @(self.riderScore); //6.骑手评星

    //评价内容
    NSString *content = self.fadeBackTextView.text ? : @""; //有就是输入的内容,没有就是空@“”

    
    NSMutableDictionary *parDicM = [NSMutableDictionary dictionary];
    
    //图片数组
    if (picNameArr.count) { //有图片就传,没有就忽略
        parDicM[@"thumbnailList"] = picNameArr;
    }
    
    parDicM[@"userOrderId"] = userOrderId;
    parDicM[@"complexStarLevel"] = complexStarLevel; //综合
    parDicM[@"serviceStarLevel"] = serviceStarLevel; //服务
    parDicM[@"tasteStarLevel"] = tasteStarLevel; //口味
//    parDicM[@"deliveryStarLevel"] = @3; //骑手
    parDicM[@"content"] = content;

    //surroundingStarLevel 1 ～ 5，若订单送餐方式deliveryType=1(自提)或deliveryType=2(预约门店)，则必传此字段，否则可为NULL
    //deliveryStarLevel   1 ～ 5若订单送餐方式deliveryType=0(自提)，则必传此字段，否则可为NULL
    switch (self.fdDeliveryType) {
        case FDDeliveryTypeZiTi:
        case FDDeliveryTypeMenDianYuYue:{
            parDicM[@"surroundingStarLevel"] = surroundingStarLevel; //环境
        }break;
        case FDDeliveryTypeWaiSong:{
            parDicM[@"deliveryStarLevel"] = deliveryStarLevel; //骑手
        }
        default:
            break;
    }
    
    FDLog(@"%ld",(long)self.fdDeliveryType);
    
    FDLog(@"请求参数:%@",parDicM);
    return [parDicM copy];
}


/**评价接口*/
- (void)requestSaveEvaluteWithPardic:(NSDictionary *)parDic {
    
    [FDHttpAPi requestUserEvaluteOrederWithParDic:parDic successBlock:^(id responseObjc) {
        NSString *event = responseObjc[@"event"];
        if ([event isEqualToString:SUCCESS]) {
            FDLog(@"评价成功");
            [JRToast showWithText:NSLocalizedString(ToastPingJiaChengGong, @"评价成功")];
            //返回上一个页面
            [self.navigationController popViewControllerAnimated:YES];
            
        }else {
            [JRToast showWithText:responseObjc[describe]];
        }
    } fialBlock:^(NSError *error) {
        FDLog(@"%@",[error localizedDescription]);
    }];
}


#pragma mark - 亚马逊云存储S3
//!!!!:上传图片,
- (void)uploadData:(NSData *)data updataPicName:(NSString *)picName picNameArr:(NSArray *)picNameArr
{
    [MBProgressHUD fd_showHUDToView:self.view];//菊花
    //Create the completion handler for the transfer
    AWSS3TransferUtilityUploadCompletionHandlerBlock completionHandler = ^(AWSS3TransferUtilityUploadTask *task, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (error) {
                [JRToast showWithText:NSLocalizedString(ToastUploadFailed, @"上传失败")];
                [MBProgressHUD fd_hideHUDFromView:self.view]; //隐藏菊花
            } else {
                
                [JRToast showWithText:NSLocalizedString(ToastUploadSuccess, @"上传成功")];
                //等待最后一个上传成功之后,在隐藏菊花。
                [MBProgressHUD fd_hideHUDFromView:self.view]; //隐藏菊花
                
                self.totalCount++;
                if (self.totalCount == self.dataArr.count) {
                    FDLog(@"最后一个上传成功，调接口");
                    //组装请求参数
                    NSDictionary *parDic = [self assembleSaveEvaluateParDicWithArr:picNameArr];
                    [self requestSaveEvaluteWithPardic:parDic];
                }
            }
        });
    };
    
    //Create the TransferUtility expression and add the progress block to it.
    //This would be needed to report on progress tracking
    AWSS3TransferUtilityUploadExpression *expression = [AWSS3TransferUtilityUploadExpression new];
    expression.progressBlock = ^(AWSS3TransferUtilityTask *task, NSProgress *progress) {
        dispatch_async(dispatch_get_main_queue(), ^{
            
        });
    };
    
    AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];
    [[transferUtility uploadData:data
                          bucket:FDAWSS3BucketName
                             key:picName
                     contentType:@"image/jpge"
                      expression:expression
               completionHandler:completionHandler] continueWithBlock:^id(AWSTask *task) {
        if (task.error) {
            NSLog(@"Error: %@", task.error);
        }
        if (task.result) {
            
        }
        return nil;
    }];
}


@end

/**
 1.拍照没处理
 2.上传图片的处理
 批量上传：什么时候上传，。
 第一个接口: 获取服务器返回的云存储凭证
 第二个接口: 调亚马逊上传图片。
 第三个接口: 调评论接口。
 有照片的时候：选择照片
 
 
3.上传多图片：
 3-1中途有上传失败的情况怎么处理？
 3-2最后一张上传成功的通知:
    3-2-1 "队列组" or
    3-2-2 "dispatch_semphore信号量" 、
    3-2-3 通知 、
    3-2-4 定义一个变量count,没成功一次++,直到count = self.dataArr.count 最后一个上传成功
 */
